package com.letu.aopcache.model;

import com.letu.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "CacheWayEnum", description = "缓存模式")
public enum CacheWayEnum implements BaseEnum {
    /**
     * HASH="hash"
     */
    HASH("HASH"),

    /**
     * MAGIC="精准模式"
     */
    MAGIC("magic")
    ;

    @ApiModelProperty(value = "描述")
    private String desc;

    /**
     * 根据当前枚举的name匹配
     */
    public static CacheWayEnum match(String val, CacheWayEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static CacheWayEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(CacheWayEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "NORMAL,WAIT_INIT,FORBIDDEN,WAITING,REFUSE,DELETE", example = "NORMAL")
    public String getCode() {
        return this.name();
    }
}
